﻿using System;

using Patterns.Cache;
using Patterns.SafeCode;

namespace Patterns.Web.Cache
{
	public class CacheProxy : ICacheProxy
	{
		private readonly System.Web.Caching.Cache _cache;

		public CacheProxy(System.Web.Caching.Cache cache)
		{
			_cache = cache;
		}

		#region Implementation of ICacheProxy

		/// <summary>
		/// 	Gets the <see cref = "System.Object" /> with the specified key.
		/// </summary>
		public object this[string key]
		{
			get { return Try.Get(() => _cache[key]); }
			set { throw new NotImplementedException(); }
		}

		/// <summary>
		/// 	Gets the item with the specified key.
		/// </summary>
		/// <typeparam name = "T"></typeparam>
		/// <param name = "key">The key.</param>
		/// <param name = "factory">The factory to run in case a replacement item is
		/// needed.</param>
		/// <remarks>Supplying a replacement factory causes the factory's result to be
		/// cached before being returned.</remarks>
		public T Get<T>(string key, Func<T> factory)
		{
			throw new NotImplementedException();
		}

		/// <summary>
		/// 	Removes the item with the specified key.
		/// </summary>
		/// <param name = "key">The key.</param>
		public ICacheProxy Remove(string key)
		{
			throw new NotImplementedException();
		}

		/// <summary>
		/// Called when an item is removed from the cache.
		/// </summary>
		/// <typeparam name="T"></typeparam>
		/// <param name="key">The key.</param>
		/// <param name="action">The action.</param>
		/// <returns></returns>
		public ICacheProxy OnRemoval<T>(string key, Action<CacheEvent<T>> action)
		{
			throw new NotImplementedException();
		}

		#endregion
	}
}
